package com.yyfax.ph.personal.authority.forgot;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.content.Loader;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import com.yyfax.common.form.LoginLayout;
import com.yyfax.common.tools.RegexUtil;
import com.yyfax.infrastructure.mvp.Presenter;
import com.yyfax.ph.R;
import com.yyfax.ph.base.BaseFragment;

public class NewPwdFragment extends BaseFragment {
	private static final String TAG = NewPwdFragment.class.getSimpleName();

	@BindView(R.id.pwd_edt)
	LoginLayout mNewCodeTv;

	Unbinder unbinder;

	private ForgotPwdActivity forgotPwdActivity;

	@Override
	public void onAttach(Context context) {
		super.onAttach(context);
		if (context instanceof Activity) {
			forgotPwdActivity = (ForgotPwdActivity) context;
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.find_code_fragment_two_layout_new, null);
		unbinder = ButterKnife.bind(this, view);
		return view;
	}

	public String getNewCode() {
		return mNewCodeTv.getText().toString().trim();
	}

	@OnClick({R.id.reset_password_btn})
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.reset_password_btn:
				String newCode = mNewCodeTv.getText().toString().trim();
				if (TextUtils.isEmpty(newCode)) {
					showToast(String.format(getString(R.string.please_input_toast), getString(R.string.new_login_password)));
					return;
				}
				if (!RegexUtil.isPassword(newCode)) {
					showToast(R.string.password_format_error_tips);
					return;
				}
				forgotPwdActivity.resetPassword();
				break;
		}
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
		unbinder.unbind();
	}

	@Override
	public void onLoadFinished(Loader<Presenter> loader, Presenter data, int placeholder) {

	}

	@Override
	public Loader<Presenter> onCreateLoader(int id, Bundle args) {
		return null;
	}
}
